package com.bw.wxy.db;

import android.content.Context;

public class UserManager {
    private DaoMaster daoMaster;
    private DaoSession daoSession;
    private Context mContext;

    public void init(Context context){
        this.mContext=context;
    }

    public DaoMaster getDaoMaster() throws Exception {
        if (mContext==null){
            throw new Exception("content is null");
        }
        if (daoMaster==null){
            DaoMaster.DevOpenHelper usercache = new DaoMaster.DevOpenHelper(mContext, "usercache");
            daoMaster=new DaoMaster(usercache.getWritableDb());
        }
        return daoMaster;
    }


    public DaoSession getDaoSession() {
        if (daoSession==null){
            try {
                daoSession=getDaoMaster().newSession();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return daoSession;
    }

    private UserManager(){};

    private static UserManager userManager;

    public static UserManager getInstance(){
        if (userManager==null){
            userManager=new UserManager();
        }
        return userManager;
    }
}

